import qs from "qs";
import axios from "axios"


const request = axios.create({
    baseURL: "http://localhost:3030",
    timeout: 5000
})

// 请求拦截器
request.interceptors.request.use(config => {
    config.method === 'post' ? config.data = qs.stringify({ ...config.data }) : config.params = { ...config.params };
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    return config;
}, error => {  //请求错误处理
    return Promise.reject(error)
})

// 响应拦截器
request.interceptors.response.use(
    response => {/* 接口成功 */
        // console.log(response.data)
        return response
    },
    //错误处理
    error => {
        return Promise.reject(error)
    })

export default request